home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Text / WASTE / WASTE 1.1.2 Distribution / WASTE Source / WEUtilities.p < prev   
Encoding:
Text File  |  1995-10-12  |  2.8 KB  |  119 lines  |  [TEXT/CWIE]

  1. unit WEUtilities;
  2.  
  3. { WASTE PROJECT }
  4. { Interface to miscellaneous utility routines }
  5. { Most routines are defined in WASTEUtils.Lib }
  6.  
  7. { Copyright © 1993-1995 Marco Piovanelli }
  8. { All Rights Reserved }
  9.  
  10. interface
  11.     uses
  12.         Types, Memory;
  13.  
  14.     const
  15.  
  16. { result codes }
  17.  
  18.         weUndefinedSelectorErr = -50;
  19.  
  20. { values for WEAllocate allocFlags parameter }
  21.  
  22.         kAllocClear = $0001;                        { clear handle after allocation }
  23.         kAllocTemp = $0002;                    { use temporary memory if available }
  24.  
  25.     type
  26.  
  27.         WEFieldDescriptor = record
  28.                 fOffset: Integer;
  29.                 fLength: Integer;
  30.             end;  { WEFieldDescriptor }
  31.  
  32.         WELookupTableElement = record
  33.                 selector: LongInt;
  34.                 desc: WEFieldDescriptor;
  35.             end;  { WELookupTableElement }
  36.         WELookupTableElementPtr = ^WELookupTableElement;
  37.  
  38.         WELookupTable = array[0..0] of WELookupTableElement;
  39.  
  40.     var
  41.  
  42. { externally defined global variables }
  43.  
  44. {$PUSH}
  45. {$J+}
  46.  
  47.         _weMainSelectorTable: WELookupTable;
  48.         _weObjectHandlerSelectorTable: WELookupTable;
  49.  
  50. {$POP}
  51.  
  52.     procedure _WEForgetHandle (var h: univ Handle);
  53.     function _WESetHandleLock (h: univ Handle;
  54.                                     lock: Boolean): Boolean;
  55.     procedure _WEBlockClr (blockPtr: Ptr;
  56.                                     blockSize: Size);
  57.     function _WEBlockCmp (block1, block2: Ptr;
  58.                                     blockSize: Size): Boolean;
  59.     function _WEInsertSlot (h: univ Handle;
  60.                                     element: univ Ptr;
  61.                                     insertAt: LongInt;
  62.                                     slotSize: Size): OSErr;
  63.     function _WERemoveSlot (h: univ Handle;
  64.                                     removeAt: LongInt;
  65.                                     slotSize: Size): OSErr;
  66.     procedure _WEReorder (var a, b: LongInt);
  67.     function _WEGetField ({const} var table: WELookupTable;
  68.                                     selector: OSType;
  69.                                     info: univ Ptr;
  70.                                     structure: univ Ptr): OSErr;
  71.     function _WESetField ({const} var table: WELookupTable;
  72.                                     selector: OSType;
  73.                                     info: univ Ptr;
  74.                                     structure: univ Ptr): OSErr;
  75.     function _WEAllocate (blockSize: Size;
  76.                                     allocFlags: Integer;
  77.                                     var h: univ Handle): OSErr;
  78.  
  79. implementation
  80.  
  81.     function _WEAllocate (blockSize: Size;
  82.                                     allocFlags: Integer;
  83.                                     var h: univ Handle): OSErr;
  84.  
  85. { Allocate a new relocatable block. }
  86. { AllocFlags may specify whether the block should be cleared and whether }
  87. { temporary memory should be used. }
  88.  
  89.         var
  90.             theHandle: Handle;
  91.             err: OSErr;
  92.     begin
  93.         theHandle := nil;
  94.  
  95. { if kAllocTemp is specified, try tapping temporary memory }
  96.         if (BAND(allocFlags, kAllocTemp) <> 0) then
  97.             theHandle := TempNewHandle(blockSize, err);
  98.  
  99. { if kAllocTemp isn't specified, or TempNewHandle failed, try with current heap }
  100.         if (theHandle = nil) then
  101.             begin
  102.                 theHandle := NewHandle(blockSize);
  103.                 err := MemError;
  104.             end;
  105.  
  106. { if kAllocClear is specified, zero the block }
  107.         if (BAND(allocFlags, kAllocClear) <> 0) then
  108.             if (theHandle <> nil) then
  109.                 _WEBlockClr(theHandle^, blockSize);
  110.  
  111. { return handle through VAR parameter }
  112.         h := theHandle;
  113.  
  114. { return result code }
  115.         _WEAllocate := err;
  116.  
  117.     end;  { _WEAllocate }
  118.  
  119. end.